#ifndef _IL_UTIL_H_
#define _IL_UTIL_H_

#include <IL/il.h>

typedef enum ilPixelFormat_tag {
  PF_COLOUR_INDEX     =IL_COLOUR_INDEX,
  PF_COLOR_INDEX      =IL_COLOR_INDEX,
  PF_RGB              =IL_RGB,
  PF_RGBA             =IL_RGBA,
  PF_BGR              =IL_BGR,
  PF_BGRA             =IL_BGRA,
  PF_LUMINANCE        =IL_LUMINANCE,
  PF_LUMINANCE_ALPHA  =IL_LUMINANCE_ALPHA
} ilPixelFormat;

typedef enum ilComponentDataType_tag {
  CDT_BYTE           =IL_BYTE,
  CDT_UNSIGNED_BYTE  =IL_UNSIGNED_BYTE,
  CDT_SHORT          =IL_SHORT,
  CDT_UNSIGNED_SHORT =IL_UNSIGNED_SHORT,
  CDT_INT            =IL_INT,
  CDT_UNSIGNED_INT   =IL_UNSIGNED_INT,
  CDT_FLOAT          =IL_FLOAT,
  CDT_DOUBLE         =IL_DOUBLE
} ilComponentDataType;

struct ImageInfo {
  ILubyte* pData;
  ILint w, h;
  ILint depth;
  ILint bpp;
  ILint size;
  ILint lump;
  ilPixelFormat format;
  ilComponentDataType componentDataType;

  static ImageInfo Get();
  static void Print(const ImageInfo& info);
};

ImageInfo ImageInfo::Get()
{
  static ImageInfo iInfo;
  iInfo.pData = ilGetData();
  iInfo.w = ilGetInteger(IL_IMAGE_WIDTH);
  iInfo.h = ilGetInteger(IL_IMAGE_HEIGHT);
  iInfo.depth = ilGetInteger(IL_IMAGE_DEPTH);
  iInfo.bpp = ilGetInteger(IL_IMAGE_BITS_PER_PIXEL);
  iInfo.size = ilGetInteger(IL_IMAGE_SIZE_OF_DATA);
  iInfo.lump = ilGetLumpPos();
  iInfo.format = (ilPixelFormat) ilGetInteger(IL_IMAGE_FORMAT);
  iInfo.componentDataType = (ilComponentDataType) ilGetInteger(IL_IMAGE_TYPE);

  return iInfo;
}

void ImageInfo::Print(const ImageInfo& info)
{
  printf("Width: %d  Height: %d  Depth: %d  Bpp: %d  Size: %d  Format: %d  Type: %d\n",
    info.w, info.h, info.depth, info.bpp, info.size, info.format, info.componentDataType);
}

#endif  // _IL_UTIL_H_
